package jmine.tec.subscription.impl;

import java.util.concurrent.atomic.AtomicLong;

import jmine.tec.annotations.Unmodifiable;
import jmine.tec.subscription.Publication;

/**
 * Implementacao abstrata de {@link Publication} que verifica se uma eh mais nova que outra pelo tempo em que foram construidas
 * 
 * @author takeshi
 */
@Unmodifiable
public abstract class AbstractPublication implements Publication {

    private static final long serialVersionUID = -6154788850331166376L;

    private final String identification;

    private static final AtomicLong ID_GENERATOR = new AtomicLong(1L);

    private final transient long version = ID_GENERATOR.getAndIncrement();

    /**
     * C'tor
     * 
     * @param identification String
     */
    public AbstractPublication(String identification) {
        this.identification = identification;
    }

    /**
     * {@inheritDoc}
     */
    public String getIdentification() {
        return this.identification;
    }

    /**
     * {@inheritDoc}
     */
    public boolean isNewerThan(Publication another) {
        if (this == another) {
            return false;
        }
        AbstractPublication abs = (AbstractPublication) another;
        return this.version > abs.version;
    }

    /**
     * @return long
     */
    public long getLocalVersion() {
        return version;
    }

}
